package musicstore.web.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import musicstore.entity.User;

public class SecurityInterceptor extends HandlerInterceptorAdapter {
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		User loginUser = (User)request.getSession().getAttribute("user");
		if (loginUser != null && loginUser.getUserRoleId()==2) {
			return true;
		} else {
			response.sendRedirect(request.getContextPath() + "/" + "login");
			return false;
		}
	}

}
